package com.hwl.lab.service;

import com.hwl.lab.entity.Family;
import com.hwl.lab.entity.Peples;
import com.hwl.lab.repository.FamilyRepository;
import com.hwl.lab.unit.UnitData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FamilyService {
    @Autowired
    private FamilyRepository familyRepository;
    @Autowired
    private UnitData unitData;
    //分页实现
    public Page<Family> findAll(Integer page, Integer size){
        Pageable pageable=  PageRequest.of(page-1,size);
        return familyRepository.findAll(pageable);
    }
    //不分页
    public List<Family> findAll() {
        return familyRepository.findAll();
    }
    //通过账号查询
    public Family findByFamilyid(String familyid){
        return familyRepository.findByFamilyid(familyid);
    }
    //保存，修改
    public Family saveFamily(Family family){
        family.setCreattime(unitData.getTime());
       return  familyRepository.save(family);
    }
    //通过账号删除
    public void deleteById(Long id){
        familyRepository.deleteById(id);
    }

    public Family findByhandname(String handname) {
        return familyRepository.findByHandname(handname);
    }
}
